<template name="studentHome">
  <ul class="courses">
    {{#each getCourses}}
      {{> studentCourseItem}}
    {{/each}}
  </ul>
</template>

<template name="studentCourseItem">
  <li class="course">
    <h3>{{name}}</h3>
    <ul class="requirements">
      {{#each getRequirementsByCourse _id}}
        {{> studentRequirementItem}}
      {{/each}}
    </ul>
  </li>
</template>

<template name="studentRequirementItem">
  <li class="requirement">
    <hr>
    <h4>{{name}}</h4>
    <p>
      截止日期 {{formatDate deadline}}
    </p>
    <p>
      {{content}}
    </p>

    {{#if getHomeworkByRequirement _id}}
      {{#with getHomeworkByRequirement _id}}
        {{> submittedHomework}}
      {{/with}}
    {{else}}
      {{> emptyHomework}}
    {{/if}}
  </li>
</template>

<template name="emptyHomework">
  {{#if dued ../deadline}}
    <div class="alert alert-warning" role="alert">
      <p>已经截止提交</p>
    </div>
  {{else}}
    <div>
      <a href="{{pathFor 'addHomework'}}" class="btn btn-info">提交</a>
    </div>
  {{/if}}
</template>


<template name="submittedHomework">
  {{#if dued ../deadline}}
    <div>
      <a href="{{pathFor 'viewHomework'}}" class="btn btn-info">查看</a>
    </div>
  {{else}}
    <a href="{{pathFor 'editHomework'}}" class="btn btn-info">修改</a>
  {{/if}}
</template>